package com.delu.controller;

import com.delu.data.Result;
import com.delu.em.ResultEnum;
import com.delu.entity.CarSeries;
import com.delu.mapper.CarSeriessMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("carSeries")
@Api("汽车系列")
public class CarSeriesController {
    @Resource
    private CarSeriessMapper carSeriessMapper;

    @GetMapping
    @ApiOperation("汽车系列管理查询")
    @ApiImplicitParam(name = "id",value = "系列ID",required = true,paramType = "query")
    public Result selectCarSeries(@RequestParam("id")Integer id){
        System.out.println("汽车系列的查询" + id);
        List<CarSeries> carSeriesList = carSeriessMapper.selectCarSeries();
        return Result.response(ResultEnum.SUCCESS).setData(carSeriesList);
    }

    @PostMapping
    @ApiOperation("汽车系列管理增加")
    @ApiImplicitParam(name = "CarSeries",value = "汽车系列实体类",required = true,paramType = "body")
    public Result insertCarSeries(@RequestBody CarSeries carSeries){
        Integer i = carSeriessMapper.insert(carSeries);
        System.out.println("汽车系列" + carSeries);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

    @PutMapping
    @ApiOperation("汽车系列管理修改")
    @ApiImplicitParam(name = "CarSeries",value = "汽车系列实体类",required = true,paramType = "body")
    public Result updateCarSeries(@RequestBody CarSeries carSeries){
        Integer i = carSeriessMapper.updateById(carSeries);
        System.out.println("汽车系列" + carSeries);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }

    @DeleteMapping
    @ApiOperation("汽车系列管理删除")
    @ApiImplicitParam(name = "id",value = "系列ID",required = true,paramType = "query")
    public Result deleteCarSeries(@RequestParam("id")Integer id){
        Integer i = carSeriessMapper.deleteById(id);
        System.out.println("汽车系列的删除" + id);
        return Result.response(ResultEnum.SUCCESS).setData(i);
    }
}
